import axios from 'axios'

const http = axios.create({
  // baseURL: 'http://192.168.12.169:8765/v1/',
  baseURL: 'http://wx.marisfrolg.com:7077/',
  withCredentials: true,
  timeout: 10000,
  headers: { 'content-type': 'application/json' }
})

function apiAxios(method, url, params, response) {
  http({
    method: method,
    url: url,
    data: method === 'POST' || method === 'PUT' ? params : null,
    params: method === 'GET' || method === 'DELETE' ? params : null
  })
    .then(function(res) {
      response(res)
    })
    .catch(function(err) {
      response(err)
    })
}

export default {
  get: function(url, params, response) {
    return apiAxios('GET', url, params, response)
  },
  post: function(url, params, response) {
    return apiAxios('POST', url, params, response)
  },
  put: function(url, params, response) {
    return apiAxios('PUT', url, params, response)
  },
  delete: function(url, params, response) {
    return apiAxios('DELETE', url, params, response)
  }
}
